<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Api\CqydApiController;
use App\Services\SoapService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Workerman\Mqtt\Protocols\Mqtt;
use Illuminate\Auth\AuthenticationException;


class TestController extends Controller
{
        //加密私钥
        const DECODE_RSA_KEN = '-----BEGIN RSA PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL/bDDonDtsYfsBD
uUZQFh+JpFAnTQC7CPkKqXkS3Edf1YBRoAfAyW45b02vVinPdkd0QldeXCsC7lYv
uFL0YohH5nH88dDo73+/ijZXwpkwlVlheO9wLRJ2Bu2If+U1LR/lPuMDLJK9/yQn
cuF1CaIEYKoLrJ8lzRMhJEhgh44LAgMBAAECgYATtqBFAWpnXNb5TnwlG2mKiAwY
KFGjN5SuckgDpsp3kwNPEhQNd+O6rbAgHVoPJcATi4CdlZaG3OA8ft7Dt1TAWjvv
tn3x6y6RbwaNrw5yTCiMECfkMLJQ/xi1EwRsWdZvHCVngNZUHdTePG2nuaFx2h60
R4uko5mjufr3Aw0j0QJBAPheKYwUq5j6nycGObyIw9KwivCbFQDoIBmW4TPh4kSp
Z1XQTXHvrpubGBg1c0pLxOTxaBXt0Kh8EE+vMFjC+9UCQQDFwFIUpmMVZLJ1sYDD
0nRTrGHXIakkvRbNgjadZibkjDNUfNDJggtI5tHYgEG3IOCPj45c2QfYskgZDacL
yrJfAkEArpXiNqnBBcQGY/QoWbL5k/ytbfxVg1GoXtSEcWfzGbjK/rNx/QkygAdB
pKLN7Afe2+Al/mQxLH4pKRpIrdxCEQJAB+x23YD1Q2wvgmvEXxRVuOyVVwtwPZqe
CUoIajInqMy9WctOimR9k0Q8cFJjT7UvilEUQUApAlPSc76KTPyoPQJBAI6kTSPp
v5FAaPSNIdU7nI/80UtfDfcH8KlEzQ+gCvk7QwYB/kvioGr3d+ZJRRU4mg5xuXEn
xN1h5lwkzTtb3WY=
-----END RSA PRIVATE KEY-----';
    /**
     * RSA加密
     * @param str
     * @return str
     */
    public function Encode_RSA($str){
        if(!$str){
            return false;
        }
        $encrypted = "";
        $private_key = self::DECODE_RSA_KEN;
        $pu_key = openssl_pkey_get_private($private_key);         //这个函数可用来判断公钥是否是可用的
        if($pu_key){
            openssl_private_encrypt($str,$encrypted,$pu_key);    //公钥加密
            $encrypted = base64_encode($encrypted);	//加密后的内容通常含有特殊字符，需要编码转换下，在网络间通过url传输时要注意base64编码是否是url安全的
        }
        return $encrypted;
    }
    //测试用
    public function test(Request $request,AuthenticationException $exception) {
        //$ss = $this->Encode_RSA('2026-07-31');
        //echo $ss;die;
        /*$SQL = 'alter table a_testitem add env tinyint(4) null default "1" comment "原始记录填写环境信息：1填写，0不填"';
        DB::statement($SQL);
        $SQL = 'alter table a_testdata_key add ishide tinyint(4) not null default "0"  comment "1-隐藏，0-显示"';
        DB::statement($SQL);
        $SQL = 'alter table a_std_tool_item_rel add line_num varchar(3) null default "" comment "检测结果行号"';
        DB::statement($SQL);
        $SQL = 'alter table a_excel_pos add test_address varchar(20) null default "" comment "检测地点"';
        DB::statement($SQL);*/
        /*$std_num = 'DL/T 1476-2023';
        $disk = Storage::disk('public');
        if(!$disk->exists('syncStd/DLT1476-2023_2.json')){
            dd('汇邦检测中心未同步该标准！');
        }
        $data = json_decode($disk->get('syncStd/DLT1476-2023_2.json'),true);
        $std_id = 0;
        $std_tool_rel_id_map = $tool_id_map = $excel_pos_id_map = $std_tool_item_rel_id_map = $item_id_map = $vol_class_id_map = $condition_key_id_map = $condition_id_map = $testdata_key_id_map = [];
        try{
            foreach ($data as $table => $item) {
                switch ($table) {
                    case 'a_tool':
                        $tool2 = DB::table('a_tool')->pluck('id','name')->toArray();
                        foreach ($item as $tool_id => $item2) {
                            if (!isset($tool2[$item2['name']])) {
                                $id = $item2['id'];
                                unset($item2['id'],$item2['ctime'],$item2['ddzy_name']);
                                $id2 = DB::table('a_tool')->insertGetId($item2);
                                $tool_id_map[$id] = $id2;
                                // return $item[$tool_id]['name'].'样品类型不存在！';
                            }else{
                                $tool_id_map[$tool_id] = $tool2[$item2['name']];
                            }
                        }
                        break;
                    case 'a_testitem':
                        if (!Schema::hasColumn('a_testitem', 'id_map')) {
                            DB::statement("alter table add column `id_map` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '试验数据上传对照项目id'");
                        }
                        if(!Schema::hasColumn('a_testitem', 'pass')){
                            DB::statement("alter table add column `id_map` tinyint(4) unsigned NULL DEFAULT '0' COMMENT '默认合格：1是，0否'");
                        }
                        $testitem2 = DB::table('a_testitem')->pluck('id','name')->toArray();
                        foreach ($item as $item_id => $item2) {
                            if (!isset($testitem2[$item2['name']])) {
                                unset($item2['id'],$item2['ctime'],$item2['ddzy_name'],$item2['id_map']);
                                $id2 = DB::table('a_testitem')->insertGetId($item2);
                                $item_id_map[$item_id] = $id2;
                                // return $item[$item_id]['name'].'项目不存在！'.$item_id;
                            }else{
                                $item_id_map[$item_id] = $testitem2[$item2['name']];
                            }
                        }
                        //因为电学试验不能加项目id，这里修改项目映射id_map
                        $testitem2 = DB::table('a_testitem')->pluck('id','id');
                        foreach ($item as $item_id => $item2) {
                            if($item2['id_map']){
                                DB::table('a_testitem')->where('id',$item_id_map[$item_id])->update([
                                    'id_map'=>$item_id_map[$item2['id_map']]
                                ]);
                            }
                        }
                        // dd($item_id_map);
                        break;
                    case 'a_standard':
                        $std_id = DB::table($table)->where('num',$std_num)->value('id');
                        if (!$std_id) {
                            unset($item['id']);
                            $std_id = DB::table($table)->insertGetId($item);
                        }
                        //将该标准下的所有项目先隐藏，后面对照项目对照到的再打开
                        DB::table('a_std_tool_item_rel')->where(['std_id'=>$std_id])->update(['ishide'=>1]);
                        // dd($files);
                        break;
                    case 'a_std_tool_rel':
                        foreach ($item as $item2) {
                            $id = $item2['id'];
                            unset($item2['id'], $item2['ctime']);
                            $item2['std_id'] = $std_id;
                            $tool_id2 = $tool_id_map[$item2['tool_id']];
                            $item2['tool_id'] = $tool_id2;
                            $info = DB::table($table)->where(['std_id'=>$std_id,'tool_id'=>$tool_id2])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $std_tool_rel_id_map[$id] = $id2;
                            }else{
                                $std_tool_rel_id_map[$id] = $info->id;
                            }
                        }
                        break;
                    case 'a_excel_pos':
                        foreach ($item as $std_tool_rel_id => $item3) {
                            foreach ($item3 as $item2) {
                                $id = $item2['id'];
                                unset($item2['id']);
                                $std_tool_rel_id2 = $std_tool_rel_id_map[$std_tool_rel_id];
                                $item2['std_tool_rel_id'] = $std_tool_rel_id2;
                                $info = DB::table($table)->where(['std_tool_rel_id'=>$std_tool_rel_id2,'name'=>$item2['name']])->first();
                                if(!$info){
                                    $id2 = DB::table($table)->insertGetId($item2);
                                    $excel_pos_id_map[$id] = $id2;
                                }else{
                                    $excel_pos_id_map[$id] = $info->id;
                                }
                            }
                        }
                        // dd($excel_pos_id_map);
                        break;
                    case 'a_std_tool_item_rel':
                        foreach ($item as $item2) {
                            // dd($item2);
                            $id = $item2['id'];
                            unset($item2['id'], $item2['ctime']);
                            $tool_id2 = $tool_id_map[$item2['tool_id']];
                            $item_id2 = $item_id_map[$item2['testitem_id']];
                            $item2['std_id'] = $std_id;
                            $item2['tool_id'] = $tool_id2;
                            $item2['testitem_id'] = $item_id2;
                            // dd($item2);
                            $info = DB::table($table)->where(['std_id'=>$std_id,'tool_id'=>$tool_id2,'testitem_id'=>$item_id2])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $std_tool_item_rel_id_map[$id] = $id2;
                            }else{
                                DB::table($table)->where(['std_id'=>$std_id,'tool_id'=>$tool_id2,'testitem_id'=>$item_id2])->update(['ishide'=>0]);  //对照项目到的显示
                                $std_tool_item_rel_id_map[$id] = $info->id;
                            }
                        }
                        // dd($item);
                        break;
                    case 'a_voltage_class':
                        foreach ($item as $item2) {
                            $id = $item2['id'];
                            unset($item2['id']);
                            $tool_id2 = $tool_id_map[$item2['tool_id']];
                            $item2['std_id'] = $std_id;
                            $item2['tool_id'] = $tool_id2;
                            $item2['std_tool_rel_id'] = $std_tool_rel_id_map[$item2['std_tool_rel_id']];
                            // dd($item2);
                            $info = DB::table($table)->where(['std_id'=>$std_id,'tool_id'=>$tool_id2,'val'=>$item2['val']])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $vol_class_id_map[$id] = $id2;
                            }else{
                                $vol_class_id_map[$id] = $info->id;
                            }
                        }
                        // dd($vol_class_id_map);
                        break;
                    case 'a_condition_key':
                        foreach ($item as $item3) {
                            foreach ($item3 as $key => $item2) {
                                $id = $item2['id'];
                                unset($item2['id']);
                                $tool_id = $tool_id_map[$item2['tool_id']];
                                $std_tool_item_rel_id2 = data_get($std_tool_item_rel_id_map,$item2['std_tool_item_rel_id'],0); //可能没有，没有的在检测中心隐藏了，不需要同步
                                if ($std_tool_item_rel_id2 === 0) {
                                    continue;
                                }
                                $item_id = $item_id_map[$item2['item_id']];
                                $item2['std_id'] = $std_id;
                                $item2['tool_id'] = $tool_id;
                                $item2['item_id'] = $item_id;
                                $item2['std_tool_item_rel_id'] = $std_tool_item_rel_id2;
                                // dd($item2);
                                $info = DB::table($table)->where(['std_tool_item_rel_id'=>$std_tool_item_rel_id2,'key'=>$item2['key']])->first();
                                if(!$info){
                                    $id2 = DB::table($table)->insertGetId($item2);
                                    $condition_key_id_map[$id] = $id2;
                                }else{
                                    $condition_key_id_map[$id] = $info->id;
                                }
                            }
                        }
                        break;
                    case 'a_condition':
                        foreach ($item as $condition_key_id => $item3) {

                            foreach ($item3 as $item2) {
                                $id = $item2['id'];
                                unset($item2['id']);
                                $condition_key_id2 = $condition_key_id_map[$item2['condition_key_id']];
                                $item2['condition_key_id'] = $condition_key_id2;
                                $vol_class_id = $item2['vol_class_id'] == 0 ? $item2['vol_class_id'] : $vol_class_id_map[$item2['vol_class_id']];
                                $item2['vol_class_id'] = $vol_class_id;
                                // dd($item3,$item2);
                                $info = DB::table($table)->where(['condition_key_id'=>$condition_key_id2,'vol_class_id'=>$vol_class_id])->first();
                                if(!$info){
                                    $id2 = DB::table($table)->insertGetId($item2);
                                    // $condition_id_map[$id] = $id2;
                                }else{
                                    // DB::table($table)->where(['condition_key_id'=>$condition_key_id2,'vol_class_id'=>$vol_class_id])->update(['val'=>$item2['val']]);
                                    // $condition_id_map[$id] = $info->id;
                                }
                            }
                        }
                        // dd($condition_id_map);
                        break;
                    case 'a_testdata_key':
                        foreach ($item as $item2) {
                            $id = $item2['id'];
                            unset($item2['id']);
                            $tool_id = $tool_id_map[$item2['tool_id']];
                            $item_id = $item_id_map[$item2['item_id']];
                            $std_tool_item_rel_id2 = data_get($std_tool_item_rel_id_map,$item2['std_tool_item_rel_id'],0); //可能没有，没有的在检测中心隐藏了，不需要同步
                            if ($std_tool_item_rel_id2 === 0) {
                                continue;
                            }
                            $item2['std_id'] = $std_id;
                            $item2['tool_id'] = $tool_id;
                            $item2['item_id'] = $item_id;
                            $item2['std_tool_item_rel_id'] = $std_tool_item_rel_id2;
                            // dd($item,$item2);
                            $info = DB::table($table)->where(['std_tool_item_rel_id'=>$std_tool_item_rel_id2,'data_key'=>$item2['data_key']])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $testdata_key_id_map[$id] = $id2;
                            }else{
                                $testdata_key_id_map[$id] = $info->id;
                            }
                        }
                        break;
                    default:
                        // code...
                        break;
                }
            }
            DB::commit();
        }catch(\Exception $exception){
            DB::rollBack();
            $errCode = $exception->getCode();
            if ($errCode == 2002) {
                return '数据库连接错误！';
            }
            return $exception->getMessage().'，errcode:'.$errCode.'，errline:'.$exception->getLine();
        }
        return '同步成功！';*/
        /*$tool1 = $data['tool'];
        $tool2 = DB::table('a_tool')->pluck('id','name')->toArray();
        foreach ($tool1 as $tool_id => $toolinfo) {
            if (!isset($tool2[$toolinfo['name']])) {
                $id = $toolinfo['id'];
                unset($toolinfo['id'],$toolinfo['ctime'],$toolinfo['ddzy_name']);
                $id2 = DB::table('a_tool')->insertGetId($toolinfo);
                $tool_id_map[$id] = $id2;
                return $tool1[$tool_id]['name'].'样品类型不存在！';
            }else{
                $tool_id_map[$tool_id] = $tool2[$toolinfo['name']];
            }
        }
        $testitem1 = $data['testitem'];
        $testitem2 = DB::table('a_testitem')->pluck('id','name')->toArray();
        foreach ($testitem1 as $item_id => $item) {
            if (!isset($testitem2[$item['name']])) {
                unset($item['id'],$item['ctime'],$item['ddzy_name']);
                $id2 = DB::table('a_testitem')->insertGetId($item);
                $item_id_map[$item_id] = $id2;
                return $testitem1[$item_id]['name'].'项目不存在！'.$item_id;
            }else{
                $item_id_map[$item_id] = $testitem2[$item['name']];
            }
        }

        //循环插入
        foreach ($data as $table => $item) {
            try{
                switch ($table) {
                    case 'a_standard':
                        $std_id = DB::table($table)->where('num',$std_num)->value('id');
                        if (!$std_id) {
                            unset($item['id']);
                            $std_id = DB::table($table)->insertGetId($item);
                        }

                        break;
                    case 'a_std_tool_rel':
                        foreach ($item as $item2) {
                            $id = $item2['id'];
                            unset($item2['id'], $item2['ctime']);
                            $item2['std_id'] = $std_id;
                            $tool_id2 = $tool_id_map[$item2['tool_id']];
                            $item2['tool_id'] = $tool_id2;
                            $info = DB::table($table)->where(['std_id'=>$std_id,'tool_id'=>$tool_id2])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $std_tool_rel_id_map[$id] = $id2;
                            }else{
                                $std_tool_rel_id_map[$id] = $info->id;
                            }
                        }
                        break;
                    case 'a_excel_pos':
                        foreach ($item as $std_tool_rel_id => $item3) {
                            foreach ($item3 as $item2) {
                                $id = $item2['id'];
                                unset($item2['id']);
                                $std_tool_rel_id2 = $std_tool_rel_id_map[$std_tool_rel_id];
                                $item2['std_tool_rel_id'] = $std_tool_rel_id2;
                                $info = DB::table($table)->where(['std_tool_rel_id'=>$std_tool_rel_id2,'name'=>$item2['name']])->first();
                                if(!$info){
                                    $id2 = DB::table($table)->insertGetId($item2);
                                    $excel_pos_id_map[$id] = $id2;
                                }else{
                                    $excel_pos_id_map[$id] = $info->id;
                                }
                            }
                        }
                        // dd($excel_pos_id_map);
                        break;
                    case 'a_std_tool_item_rel':
                        foreach ($item as $item2) {
                            $id = $item2['id'];
                            unset($item2['id'], $item2['ctime']);
                            $tool_id2 = $tool_id_map[$item2['tool_id']];
                            $item_id2 = $item_id_map[$item2['testitem_id']];
                            $item2['std_id'] = $std_id;
                            $item2['tool_id'] = $tool_id2;
                            $item2['testitem_id'] = $item_id2;
                            // dd($item2);
                            $info = DB::table($table)->where(['std_id'=>$std_id,'tool_id'=>$tool_id2,'testitem_id'=>$item_id2])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $std_tool_item_rel_id_map[$id] = $id2;
                            }else{
                                $std_tool_item_rel_id_map[$id] = $info->id;
                            }
                        }
                        // dd($std_tool_item_rel_id_map);
                        break;
                    case 'a_voltage_class':
                        foreach ($item as $item2) {
                            $id = $item2['id'];
                            unset($item2['id']);
                            $tool_id2 = $tool_id_map[$item2['tool_id']];
                            $item2['std_id'] = $std_id;
                            $item2['tool_id'] = $tool_id2;
                            $item2['std_tool_rel_id'] = $std_tool_rel_id_map[$item2['std_tool_rel_id']];
                            // dd($item2);
                            $info = DB::table($table)->where(['std_id'=>$std_id,'tool_id'=>$tool_id2,'val'=>$item2['val']])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $vol_class_id_map[$id] = $id2;
                            }else{
                                $vol_class_id_map[$id] = $info->id;
                            }
                        }
                        // dd($vol_class_id_map);
                        break;
                    case 'a_condition_key':
                        foreach ($item as $item3) {
                            foreach ($item3 as $key => $item2) {
                                $id = $item2['id'];
                                unset($item2['id']);
                                $tool_id = $tool_id_map[$item2['tool_id']];
                                $std_tool_item_rel_id2 = $std_tool_item_rel_id_map[$item2['std_tool_item_rel_id']];
                                $item_id = $item_id_map[$item2['item_id']];
                                $item2['std_id'] = $std_id;
                                $item2['tool_id'] = $tool_id;
                                $item2['item_id'] = $item_id;
                                $item2['std_tool_item_rel_id'] = $std_tool_item_rel_id2;
                                // dd($item2);
                                $info = DB::table($table)->where(['std_tool_item_rel_id'=>$std_tool_item_rel_id2,'key'=>$item2['key']])->first();
                                if(!$info){
                                    $id2 = DB::table($table)->insertGetId($item2);
                                    $condition_key_id_map[$id] = $id2;
                                }else{
                                    $condition_key_id_map[$id] = $info->id;
                                }
                            }
                        }
                        // dd($condition_key_id_map);
                        break;
                    case 'a_condition':
                        foreach ($item as $condition_key_id => $item3) {

                            foreach ($item3 as $item2) {
                                $id = $item2['id'];
                                unset($item2['id']);
                                $condition_key_id2 = $condition_key_id_map[$item2['condition_key_id']];
                                $item2['condition_key_id'] = $condition_key_id2;
                                $vol_class_id = $item2['vol_class_id'] == 0 ? $item2['vol_class_id'] : $vol_class_id_map[$item2['vol_class_id']];
                                $item2['vol_class_id'] = $vol_class_id;
                                // dd($item3,$item2);
                                $info = DB::table($table)->where(['condition_key_id'=>$condition_key_id2,'vol_class_id'=>$vol_class_id])->first();
                                if(!$info){
                                    $id2 = DB::table($table)->insertGetId($item2);
                                    // $condition_id_map[$id] = $id2;
                                }else{
                                    // $condition_id_map[$id] = $info->id;
                                }
                            }
                        }
                        // dd($condition_id_map);
                        break;
                    case 'a_testdata_key':
                        foreach ($item as $item2) {
                            $id = $item2['id'];
                            unset($item2['id']);
                            $tool_id = $tool_id_map[$item2['tool_id']];
                            $item_id = $item_id_map[$item2['item_id']];
                            $std_tool_item_rel_id2 = $std_tool_item_rel_id_map[$item2['std_tool_item_rel_id']];
                            $item2['std_id'] = $std_id;
                            $item2['tool_id'] = $tool_id;
                            $item2['item_id'] = $item_id;
                            $item2['std_tool_item_rel_id'] = $std_tool_item_rel_id2;
                            // dd($item,$item2);
                            $info = DB::table($table)->where(['std_tool_item_rel_id'=>$std_tool_item_rel_id2,'data_key'=>$item2['data_key']])->first();
                            if(!$info){
                                $id2 = DB::table($table)->insertGetId($item2);
                                $testdata_key_id_map[$id] = $id2;
                            }else{
                                $testdata_key_id_map[$id] = $info->id;
                            }
                        }
                        break;
                    default:
                        // code...
                        break;
                }
            }catch(\Exception $exception){
                return $exception->getMessage().' ErrorCode:'.$exception->getCode();
            }
        }
        return 'OK！';*/

        //echo ini_get('post_max_size'); // 打印 post_max_size 的值
        //$ds = DB::table('a_sample_info as s')->leftjoin('a_contract_gaiyao as c','s.contract_gaiyao_id','=','c.id')->where('s.id',37)->select('c.tool_id')->first();
        //$data_input_job='002081100000000000206321';
        //$third_id = DB::table('a_third_data')->where('bar_code',$data_input_job)->orWhere('third_id2',$data_input_job)->value('third_id');
        //dd($third_id);
        //header('Content-Type:text/xml;charset=utf-8');
        // 关闭wsdl缓存
        ini_set('soap.wsdl_cache_enabled', "0");
        ini_set('soap.wsdl_cache_ttl',0);
        ini_set('default_socket_timeout', 30);
        ini_set('max_input_vars', 30);
        try {
            $url = 'http://test.nxndjc.com/services/TjOutBoundService?wsdl';
            //$url = 'http://test.nxndjc.com/services/OutBoundService?wsdl';
            //$url = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl";
            //$url = 'https://66af-27-186-228-64.ngrok-free.app/services/OutBoundService?wsdl';
            $soap = new \SoapClient($url);
            //$soap->__setSoapHeaders(new \SoapHeader('namespace', 'header', $header_value));
            echo '<pre>';
            var_dump('打印方法',$soap->__getFunctions());   //打印方法
            var_dump('打印参数类型',$soap->__getTypes());       //打印参数类型
            var_dump('最后一次请求的头数据',$soap->__getLastRequestHeaders());       //最后一次请求的头数据
            var_dump('最后一次请求的数据',$soap->__getLastRequest());       //最后一次请求的数据
            var_dump('最后一次返回的头数据',$soap->__getLastResponseHeaders());       //最后一次返回的头数据
            var_dump('最后一次返回的数据:',$soap->__getLastResponse());       //最后一次返回的数据
            echo '</pre>';
            /*$data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.sgcc.com/">
	<soapenv:Header/>
	<soapenv:Body><web:sendOutBoundData><param><![CDATA[
		<o>
			<items class="array">
				<item class="object">
					<prid type="string">605011fba4594627854e8566e771e8f5</prid>
					<blgProvince type="string">绝缘安全工器具</blgProvince>
					<checkType type="string">0</checkType>
					<deleteFlag type="string">1</deleteFlag>
					<gqjClass type="string">绝缘操作杆</gqjClass>
					<gqjStandard type="string">AC10kV</gqjStandard>
					<kindId type="string">029080000000000000037065</kindId>
					<voltageGrade type="string">5</voltageGrade>
				</item>
				<item class="object">
					<prid type="string">63e0a783e0164c329b69d3d455865bd9</prid>
					<blgProvince type="string">绝缘安全工器具</blgProvince>
					<checkType type="string">0</checkType>
					<deleteFlag type="string">1</deleteFlag>
					<gqjClass type="string">验电器</gqjClass>
					<gqjStandard type="string">GDY型,适用于AC110kV</gqjStandard>
					<kindId type="string">029080000000000000883853</kindId>
					<voltageGrade type="string">9</voltageGrade>
				</item>
				<item class="object">
					<prid type="string">8d03f4836d5a4c94b57f05dc14d95421</prid>
					<blgProvince type="string">绝缘安全工器具</blgProvince>
					<checkType type="string">0</checkType>
					<deleteFlag type="string">1</deleteFlag>
					<gqjClass type="string">绝缘操作杆</gqjClass>
					<gqjStandard type="string">AC10kV</gqjStandard>
					<kindId type="string">029080000000000000086407</kindId>
					<voltageGrade type="string">5</voltageGrade>
				</item>
				<item class="object">
					<prid type="string">71c0d0be6a3146269de6cf0484fde41a</prid>
					<blgProvince type="string"> 登高工器具</blgProvince>
					<checkType type="string">1</checkType>
					<deleteFlag type="string">1</deleteFlag>
					<gqjClass type="string">绝缘软梯</gqjClass>
					<gqjStandard type="string">调节型,$400mm</gqjStandard>
					<kindId type="string">006081100000000000206391</kindId>
					<voltageGrade type="string">10kV</voltageGrade>
				</item>
				<item class="object">
					<prid type="string">71c0d0be6a3146269de6cf0484fde41b</prid>
					<blgProvince type="string"> 登高工器具</blgProvince>
					<checkType type="string">1</checkType>
					<deleteFlag type="string">1</deleteFlag>
					<gqjClass type="string">绝缘软梯</gqjClass>
					<gqjStandard type="string">调节型,$400mm</gqjStandard>
					<kindId type="string">006081100000000000206377</kindId>
					<voltageGrade type="string">10kV</voltageGrade>
				</item>
				<item class="object">
					<prid type="string">c8e2aa1dab714b24afd141af713e184b</prid>
					<blgProvince type="string">绝缘安全工器具</blgProvince>
					<checkType type="string">2</checkType>
					<deleteFlag type="string">1</deleteFlag>
					<gqjClass type="string">绝缘操作杆</gqjClass>
					<gqjStandard type="string">AC500kV</gqjStandard>
					<kindId type="string">080000000000000002816</kindId>
					<voltageGrade type="string"></voltageGrade>
				</item>
			</items>
		</o>      ]]></param>
		</web:sendOutBoundData>
	</soapenv:Body>
</soapenv:Envelope>';
            $data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.sgcc.com/">
	<soapenv:Header/>
		<soapenv:Body>
			<web:sendOutBoundData>
				<param>
				<![CDATA[
					<o>
						 <items class="array">
							<item class="object">
								<prid type="string">181b66d925774d6994aa37b8469b4fb8</prid>
								<blgProvince type="string">登高工器具</blgProvince>
								<checkType type="string">1</checkType>
								<deleteFlag type="string">1</deleteFlag>
								<gqjClass type="string">快装脚手架</gqjClass>
								<gqjStandard type="string">快装脚手架</gqjStandard>
								<kindId type="string">029080000000000002768127</kindId>
								<voltageGrade type="string"></voltageGrade>
							</item>
						  <item class="object">
							<prid type="string">c1116bb7903d41748c3bfeeb5c22b601</prid>
							<blgProvince type="string">登高工器具</blgProvince>
							<checkType type="string">1</checkType>
							<deleteFlag type="string">1</deleteFlag>
							<gqjClass type="string">快装脚手架</gqjClass>
							<gqjStandard type="string">快装脚手架</gqjStandard>
							<kindId type="string">029080000000000002768073</kindId>
							<voltageGrade type="string"></voltageGrade>
						  </item>
						  <item class="object">
							<prid type="string">c8b18642e6904913a0ab0c3970367abd</prid>
							<blgProvince type="string">登高工器具</blgProvince>
							<checkType type="string">1</checkType>
							<deleteFlag type="string">1</deleteFlag>
							<gqjClass type="string">快装脚手架</gqjClass>
							<gqjStandard type="string">快装脚手架</gqjStandard>
							<kindId type="string">029080000000000002768110</kindId>
							<voltageGrade type="string"></voltageGrade>
							</item>
						  <item class="object">
							<prid type="string">0c77b2fcde2140a2991795c5900decc8</prid>
							<blgProvince type="string">登高工器具</blgProvince>
							<checkType type="string">1</checkType>
							<deleteFlag type="string">1</deleteFlag>
							<gqjClass type="string">快装脚手架</gqjClass>
							<gqjStandard type="string">快装脚手架</gqjStandard>
							<kindId type="string">029080000000000002768103</kindId>
							<voltageGrade type="string"></voltageGrade>
							</item>
						  <item class="object">
							<prid type="string">270e9486b09d42bcb4776d5ddcc5bebd</prid>
							<blgProvince type="string">登高工器具</blgProvince>
							<checkType type="string">1</checkType>
							<deleteFlag type="string">1</deleteFlag>
							<gqjClass type="string">快装脚手架</gqjClass>
							<gqjStandard type="string">快装脚手架</gqjStandard>
							<kindId type="string">029080000000000002768080</kindId>
							<voltageGrade type="string"></voltageGrade>
							</item>
						  <item class="object">
							<prid type="string">290aae403689481594b5f077597d395e</prid>
							<blgProvince type="string">登高工器具</blgProvince>
							<checkType type="string">1</checkType>
							<deleteFlag type="string">1</deleteFlag>
							<gqjClass type="string">快装脚手架</gqjClass>
							<gqjStandard type="string">快装脚手架</gqjStandard>
							<kindId type="string">029080000000000002768097</kindId>
							<voltageGrade type="string"></voltageGrade>
							</item>
						</items>
					</o>
]]>   </param>
</web:sendOutBoundData>   </soapenv:Body>   </soapenv:Envelope>';*/
            $data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices.sgcc.com/">	<soapenv:Header/>	<soapenv:Body>	<web:sendOutBoundData>	<param>
				<![CDATA[
					<o>
					<items class="array">
						<item class="object">
							<prid type="string">71c0d0be6a3146269de6cf0484fdessb</prid>
							<blgProvince type="string">个体防护装备</blgProvince>
							<checkType type="string">2</checkType>
							<deleteFlag type="string">1</deleteFlag>
							<gqjClass type="string">导电鞋</gqjClass>
							<gqjStandard type="string">白色,导电鞋</gqjStandard>
							<kindId type="string">002081100000000000206322</kindId>
							<voltageGrade type="string"></voltageGrade>
						</item>
					</items>
					</o>
				]]>
			</param>
		</web:sendOutBoundData>	</soapenv:Body></soapenv:Envelope>';
            // 以下两种调用方式

            try {
                $getXml = $soap->tjsendOutBoundData(array('param'=>$data)); //天净元光
            } catch (SoapFault $fault) {
                echo "Error: " . $fault->getMessage();
                echo "Request: " . $soap->__getLastRequest();
                echo "Response: " . $soap->__getLastResponse();
            }


            //$getXml = $soap->sendOutBoundData(array('param'=>$data));
            //$ss = new \App\Services\SoapService();
            //$getXml = $ss->sendOutBoundData($data);
            //$ss = new \App\Services\TjSoapService();
            //$getXml = $ss->tjsendOutBoundData($data);
            //$xmlObject = simplexml_load_string($getXml->return);
            //$saveRes = $xmlObject->asXML();
            dd($getXml->return);

            //$getXml = json_decode($getXml);
            //var_dump(get_object_vars($getXml));
            //$getXml = $soap->__soapCall('getRiskGqjData',array('param'=>$data));
            //var_dump($getXml);die;
        }catch(\SoapFault $e){
            echo "Soap error :".$e->getMessage();
        }catch(\Exception $e) {
            echo "Exception error :" . $e->getMessage();
        }
        die;
        /*var_dump(file_exists('./Service.php'));
        var_dump(file_exists('./SoapDiscovery.class.php'));
        die;
        $url = "http://www.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl";    //国内飞机航班时刻表 WEB 服务
        $url = "http://www.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl";   //中国电视节目预告（电视节目表） WEB 服务
        $url = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"; //腾讯QQ在线状态 WEB 服务
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);
        echo '<pre>';
        var_dump($output);*/
        $data = '"<soapenv:Envelope xmlns:soapenv=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:web=\"http:\/\/webservices.sgcc.com\/\"><soapenv:Header\/><soapenv:Body><web:saveExperimentData><param><![CDATA[ <o><items class=\"array\"><item class=\"object\"><prid type=\"string\">71c0d0be6a3146269de6cf0484fde40d<\/prid><inspectDate type=\"string\">2023-08-29 00:00:00<\/inspectDate><inspectTemp type=\"string\">32<\/inspectTemp><inspectHumidity type=\"string\">65<\/inspectHumidity><inspectPressure type=\"string\">100<\/inspectPressure><inspectEquipment type=\"string\"><\/inspectEquipment><inspectModel type=\"string\"><\/inspectModel><testDataArray class=\"array\"><testData class=\"object\"><TEST1 type=\"string\">4900<\/TEST1><TEST2 type=\"string\">5<\/TEST2><testProject type=\"string\">\u9759\u8d1f\u8377\u8bd5\u9a8c<\/testProject><projectResult type=\"string\">0<\/projectResult><\/testData><\/testDataArray><\/item><item class=\"object\"><prid type=\"string\">71c0d0be6a3146269de6cf0484fde41b<\/prid><inspectDate type=\"string\">2023-08-29 00:00:00<\/inspectDate><inspectTemp type=\"string\">32<\/inspectTemp><inspectHumidity type=\"string\">65<\/inspectHumidity><inspectPressure type=\"string\">100<\/inspectPressure><inspectEquipment type=\"string\"><\/inspectEquipment><inspectModel type=\"string\"><\/inspectModel><testDataArray class=\"array\"><testData class=\"object\"><TEST1 type=\"string\">3500<\/TEST1><TEST2 type=\"string\">5<\/TEST2><testProject type=\"string\">\u9759\u8d1f\u8377\u8bd5\u9a8c<\/testProject><projectResult type=\"string\">0<\/projectResult><\/testData><\/testDataArray><\/item><\/items><\/o>]]><\/param><\/web:saveExperimentData><\/soapenv:Body><\/soapenv:Envelope>"';
        $data = '<?xml version="1.0" encoding="UTF-8"?><o><resultValue><items class="array"><e class="object"><msg type="string">系无数据插入或已存在该数据！</msg><prid type="string">71c0d0be6a3146269de6cf0484fde40a</prid></e><e class="object"><msg type="string">系统数据插入或已存在该数据！</msg><prid type="string">71c0d0be6a3146269de6cf0484fde40b</prid></e></items></resultValue><successfultype="boolean">false</successful></o>';
        /*$ch = curl_init();
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_TIMEOUT,0);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_HEADER,false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));
        $res = curl_exec($ch);
        if(curl_errno($ch)){
            echo 'Error:'.curl_error($ch);
        }
        curl_close($ch);
        var_dump($res);
        echo '</pre>';
        die;*/
        /*$getXml = '<?xml version="1.0" encoding="UTF-8"?><o><resultValue><items class="array"><e class="object"><msg type="string">系统无数据插入或已存在该数据！</msg><prid type="string">71c0d0be6a3146269de6cf0484fde40a</prid></e><e class="object"><msg type="string">系统无数据插入或已存在该数据！</msg><prid type="string">71c0d0be6a3146269de6cf0484fde40b</prid></e></items></resultValue><successful type="boolean">false</successful></o>';
        $xml = json_encode(simplexml_load_string($getXml));
        $xml = json_decode($xml,true);
        dd($xml);*/

        //测试列队上传风控数据
        $data_input_job = '2300100001';
        $third_id = DB::table('a_third_data')->where('bar_code',$data_input_job)->orWhere('third_id2',$data_input_job)->value('third_id');
        $sample_info = DB::table('a_sample_info')->where('bar_code', $data_input_job)->orWhere('third_id', $data_input_job)->orderBy('id','desc')->first(); //山东国网工器具编号
        if(!$third_id || !$sample_info){
            info('UploadGwDataJob:$third_id or $sample_info Missing Parameter');
            return false;
        }
        //判断是否做完，或者第一项实验项目不合格
        $res = DB::table('a_item_data')->where('sample_info_id',$sample_info->id)->get()->toArray();
        if(!$res){
            info($data_input_job.'->该样品没有试验项目！！');
            return false;
        }
        $biaozhi = 0;   //标记是否全部完成变量
        foreach($res as $key=>$val){        //结论,0-不符合，1-符合，2-未录入,3-未试验
            if($val->res == 1){
                $biaozhi = 1;
            }
        }
        //调用上传功能
        if($biaozhi){
            //code...
            $sample_ids = [$sample_info->id];
            $third_ids =[$third_id];
            request()->offsetSet('third_ids',$third_ids);
            request()->offsetSet('sample_ids',$sample_ids);
            $thirdCon = new \App\Http\Controllers\Admin\ThirdController();
            $uploadRes = $thirdCon->uploadRes(); //成功返回1，不成功返回错误信息
            info('上传结束，状态码：'.$uploadRes);
        }else{
            info('样品编号：'.$data_input_job.' 尚未做完全部试验项目！！');
        }
        dd('走完流程了biaozhi:'.$biaozhi);





        $SQL = 'alter table a_tool add third_id varchar(100) not null default "" comment "第三方内网Id"';
        DB::statement($SQL);
        $SQL = 'alter table a_testitem add third_id text  comment "第三方内网Id"';
        DB::statement($SQL);
        $SQL = 'alter table a_contract_gaiyao add third_status tinyint(1) not null default "0" comment "第三方的数据来源（1：台账；2：储备库）"';
        DB::statement($SQL);
        $SQL = 'alter table a_contract add third_id varchar(100) not null default "" comment "第三方的送检ID上传数据时要用"';
        DB::statement($SQL);
        dd("statement");
//        set_time_limit(0);
//        ini_set('max_execution_time', 0);
//        ini_set('memory_limit', '-1');
//        $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
//        $items = DB::table('a_std_tool_item_rel as a')
//                ->leftJoin('a_tool as b','a.tool_id','=','b.id')
//                ->leftJoin('a_standard as c','a.std_id','=','c.id')
//                ->leftJoin('a_testitem as d','a.testitem_id','=','d.id')
//                ->select('b.name as tool_name','c.num as std_num','d.name as item_name')
//                ->get();
//        $std_tool_rel = DB::table('a_std_tool_rel as a')
//                ->leftJoin('a_tool as b','a.tool_id','=','b.id')
//                ->leftJoin('a_standard as c','a.std_id','=','c.id')
//                ->select('a.cycle','b.name as tool_name','c.num as std_num')
//                ->get();
//        $tool_std_items = [];
//        foreach ($items as $item) {
//            $key = $item->tool_name."|".$item->std_num;
//            if (isset($tool_std_items[$key])) {
//                // code...
//                $tool_std_items[$key] .= ','.$item->item_name;
//            }else{
//                $tool_std_items[$key] = $item->item_name;
//            }
//        }
//        $tool_std_cycle = [];
//        foreach ($std_tool_rel as $item) {
//            $key = $item->tool_name."|".$item->std_num;
//            if (isset($tool_std_cycle[$key])) {
//                // code...
//                $tool_std_cycle[$key] .= ','.$item->cycle;
//            }else{
//                $tool_std_cycle[$key] = $item->cycle;
//            }
//        }
//        $arr = [];
//        foreach ($tool_std_items as $key => $item) {
//            $keys = explode('|',$key);
//
//            $arr[] = [
//                'tool_name'=>$keys[0],
//                'std_num'=>$keys[1],
//                'item_names'=>$item,
//                'cycle'=>isset($tool_std_cycle[$key]) ? $tool_std_cycle[$key]:'',
//            ];
//        }
//
//        $sheet = $spreadsheet->getActiveSheet();
//
//        $sheet->setCellValue('A1', '序号');
//        $sheet->setCellValue('B1', '工器具名称');
//        $sheet->setCellValue('C1', '检测标准');
//        $sheet->setCellValue('D1', '检验周期（年）');
//        $sheet->setCellValue('E1', '试验项目');
//
//        $i = 2;
//        foreach( $arr as $k => $v ){
//            $sheet->setCellValue('A'.$i, $k+1);
//            $sheet->setCellValue('B'.$i, $v['tool_name']);
//            $sheet->setCellValue('C'.$i, $v['std_num']);
//            $sheet->setCellValue('D'.$i, $v['cycle']);
//            $sheet->setCellValue('E'.$i, $v['item_names']);
//            $i ++;
//        }
//
//
//        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
//
//        $writer->save( storage_path() . '/student.xlsx');
//        # 需要下载
//        $file = storage_path() . '/student.xlsx';
//
//        return  response() -> download($file);
//
//        dd(111);
//        $app_names = get_databases();
//       // dd($app_names);
//        $ERROR = [];
//        foreach($app_names as $appName) {
//            $table = 'a_hb6303';
//            $column = 'ip_port';
//            try{
//                if(Schema::connection("mysql_{$appName}")->hasTable($table)) {
//                    if(Schema::connection("mysql_{$appName}")->hasColumn($table, $column)) {
//                        try {
//                            DB::connection("mysql_{$appName}")->statement("ALTER TABLE `a_hb6303`
//MODIFY COLUMN `ip_port`  varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '局域网IP:port'
//");
//                            // ALTER TABLE `station_up_param` DROP INDEX `station_name_param`
//                            // ALTER TABLE `a_testdata_key` DROP FOREIGN KEY `a_testdata_key_ibfk_1`;
//
//// ALTER TABLE `a_testdata_key` ADD CONSTRAINT `station_up_param` FOREIGN KEY (`station_up_param`) REFERENCES `station_up_param` (`param`) ON DELETE NO ACTION ON UPDATE CASCADE;
//
//                            // ALTER TABLE `a_testdata_key` DROP FOREIGN KEY `a_testdata_key_ibfk_1`
//                            // ALTER TABLE `a_testdata_key` ADD FOREIGN KEY (`station_up_param`) REFERENCES `station_up_param` (`param`) ON DELETE NO ACTION ON UPDATE CASCADE;
//
//                            // ALTER TABLE `a_testdata_key` ADD FOREIGN KEY (`station_up_param`) REFERENCES `station_up_param` (`param`) ON DELETE NO ACTION ON UPDATE CASCADE
//                            // ALTER TABLE `a_testdata_key` ADD FOREIGN KEY (`station_up_param`) REFERENCES `station_up_param` (`param`) ON DELETE NO ACTION ON UPDATE CASCADE
//                            // ALTER TABLE `a_input_data` DROP FOREIGN KEY `a_input_data_ibfk_1`
//                            // ALTER TABLE `a_input_data` ADD CONSTRAINT `a_input_data_ibfk_1` FOREIGN KEY (`testdata_key_id`) REFERENCES `a_testdata_key` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
////
//                            // DB::connection("mysql_{$appName}")->statement("ALTER TABLE `a_gqj_plate` add INDEX `barcode_name`");
//                            // DB::connection("mysql_{$appName}")->statement("ALTER TABLE `a_gqj_plate` DROP FOREIGN KEY `gqj_plate_bar_code_1st`");
//                        }catch(\Exception $exception){
//                       // dd($appName,$exception->getMessage());
//                            array_push($ERROR, $appName);
//                        }
//                    }
//                    else {
//                        array_push($ERROR, $appName);
//                    }
//                }
//                else {
////                DB::connection("mysql_{$appName}")->statement("");
//                    $ERROR['no'][] = $appName;
//                }
//            }catch(\Exception $e){
//                dump($appName,$e->getMessage());
//                die();
//            }
//
//        }
//        dd($ERROR);


        // //空载负载
        // $data2 = json_decode('{"Id":0,"ProNum":"100011","Unit":"汇邦电气","Date":"2022-04-03","Type":"S9","Connect":"Dyn11","RatedCapacity":50.0,"ZuKang":4.0,"HVoltage":10.0,"LVoltage":0.4,"HCurrent":2.89,"LCurrent":72.17,"KongZai90_Json":"{\"Uab\":361.127,\"Ubc\":359.264,\"Uca\":356.952,\"Uv\":359.114,\"Uabv\":362.295,\"Ubcv\":360.947,\"Ucav\":358.13,\"Uvv\":360.457,\"Iab\":0.0,\"Ibc\":0.0,\"Ica\":0.0,\"Iv\":0.0,\"Pa\":0.0,\"Pb\":0.0,\"Pc\":0.0,\"Psum\":0.0,\"Pay\":0.0,\"Pby\":0.0,\"Pcy\":0.0,\"SunHao\":0.0,\"Current\":0.0,\"Hz\":49.99}","KongZai100_Json":"{\"Uab\":401.774,\"Ubc\":399.374,\"Uca\":396.352,\"Uv\":399.167,\"Uabv\":403.015,\"Ubcv\":401.105,\"Ucav\":397.572,\"Uvv\":400.564,\"Iab\":0.0,\"Ibc\":0.0,\"Ica\":0.0,\"Iv\":0.0,\"Pa\":0.0,\"Pb\":0.0,\"Pc\":0.0,\"Psum\":0.0,\"Pay\":0.0,\"Pby\":0.0,\"Pcy\":0.0,\"SunHao\":0.0,\"Current\":0.0,\"Hz\":50.019}","KongZai110_Json":"{\"Uab\":440.516,\"Ubc\":439.467,\"Uca\":436.523,\"Uv\":438.835,\"Uabv\":441.789,\"Ubcv\":441.218,\"Ucav\":437.773,\"Uvv\":440.26,\"Iab\":0.0,\"Ibc\":0.0,\"Ica\":0.0,\"Iv\":0.0,\"Pa\":0.0,\"Pb\":0.0,\"Pc\":0.0,\"Psum\":0.0,\"Pay\":0.0,\"Pby\":0.0,\"Pcy\":0.0,\"SunHao\":0.0,\"Current\":0.0,\"Hz\":50.031}","FuZai_Json":"{\"ShiPinTemp\":0.0,\"Uab\":440.203,\"Ubc\":438.196,\"Uca\":435.428,\"Uv\":437.942,\"Iab\":2.917,\"Ibc\":2.849,\"Ica\":2.909,\"Iv\":2.892,\"Pa\":271.347,\"Pb\":267.636,\"Pc\":298.292,\"Psum\":837.276,\"SunHao\":1036.787,\"ZukangV\":4.545}","NaiYa_Json":"{\"A_V\":800.84,\"B_V\":801.139,\"C_V\":800.61,\"A_I\":0.617,\"B_I\":0.753,\"C_I\":0.755,\"HZ\":149.989,\"Time\":20.0}"}',true);
        // dd($indata,$data,json_decode($data2['FuZai_Json'],true));

        // //绕组电阻测量+电压比测量和联结组标号检定
        // dd(json_decode('{"ProNum":"11111","Date":null,"Type":null,"Connect":"Dyn11","RatedCapacity":50.0,"HVoltage":10.0,"LVoltage":0.4,"HCurrent":10.0,"LCurrent":0.4,"FenJieJiCha":"±1×1.25","ZhiZu_H_Json":"[{\\"FenJie\\":1,\\"AB\\":\\"11\\",\\"BC\\":\\"11\\",\\"CA\\":\\"11\\",\\"R_V\\":11.0,\\"AmplaceH\\":0.0},{\\"FenJie\\":2,\\"AB\\":\\"11\\",\\"BC\\":\\"11\\",\\"CA\\":\\"11\\",\\"R_V\\":11.0,\\"AmplaceH\\":0.0},{\\"FenJie\\":3,\\"AB\\":\\"11\\",\\"BC\\":\\"11\\",\\"CA\\":\\"11\\",\\"R_V\\":11.0,\\"AmplaceH\\":0.0}]","ZhiZu_L_Json":"{\\"ab\\":\\"11\\",\\"bc\\":\\"11\\",\\"ca\\":\\"11\\",\\"R_V\\":11.0,\\"AmplaceL\\":0.0}","ZhiZu_L0_Json":"{\\"a0\\":\\"11\\",\\"b0\\":\\"11\\",\\"c0\\":\\"11\\",\\"R_V\\":11.0,\\"AmplaceL\\":0.0}","BianBi_Json":"[{\\"FenJieNum\\":1,\\"VoltageRatio\\":11.0,\\"AVoltageRatio\\":11.0,\\"BVoltageRatio\\":11.0,\\"CVoltageRatio\\":11.0,\\"APolar\\":\\"-\\",\\"BPolar\\":\\"-\\",\\"CPolar\\":\\"-\\",\\"AErrorRatio\\":0.0,\\"BErrorRatio\\":0.0,\\"CErrorRatio\\":0.0},{\\"FenJieNum\\":2,\\"VoltageRatio\\":11.0,\\"AVoltageRatio\\":11.0,\\"BVoltageRatio\\":11.0,\\"CVoltageRatio\\":11.0,\\"APolar\\":\\"-\\",\\"BPolar\\":\\"-\\",\\"CPolar\\":\\"-\\",\\"AErrorRatio\\":0.0,\\"BErrorRatio\\":0.0,\\"CErrorRatio\\":0.0},{\\"FenJieNum\\":3,\\"VoltageRatio\\":11.0,\\"AVoltageRatio\\":11.0,\\"BVoltageRatio\\":11.0,\\"CVoltageRatio\\":11.0,\\"APolar\\":\\"-\\",\\"BPolar\\":\\"-\\",\\"CPolar\\":\\"-\\",\\"AErrorRatio\\":0.0,\\"BErrorRatio\\":0.0,\\"CErrorRatio\\":0.0}]","BianBiLJZ_Json":"{\\"Connect\\":\\"Dyn11\\"}"}',true));

        // //绝缘+工频
        // dd(json_decode('{"ProNum":"10001","Connect":"Yyn0","RatedCapacity":"10","HVoltage":10.0,"LVoltage":0.4,"HCurrent":0.58,"LCurrent":14.43,"FenJieJiCha":"01.25","JueYuan_json":"[{\"Id\":0,\"TestPoint\":\"高压—低压及地\",\"Resistance15s\":\" 23.2GΩ\",\"Resistance60s\":\" 32.4GΩ\",\"Absorptivity\":\"1.39\"},{\"Id\":1,\"TestPoint\":\"低压—高压及地\",\"Resistance15s\":\" 22.1GΩ\",\"Resistance60s\":\" 39.8GΩ\",\"Absorptivity\":\"1.80\"}]","GongPin_json":"[{\"Id\":1,\"TestPoint\":\"低压\",\"LoadV\":\"0.4kV\",\"Result\":\"合格\"},{\"Id\":0,\"TestPoint\":\"高压\",\"LoadV\":\"10kV\",\"Result\":\"合格\"}]"}',true));
        // //空载+耐压
        // dd(json_decode('{"Id":0,"ProNum":"100011","Unit":"汇邦电气","Date":"2022-04-03","Type":"S9","Connect":"Dyn11","RatedCapacity":50.0,"ZuKang":4.0,"HVoltage":10.0,"LVoltage":0.4,"HCurrent":2.89,"LCurrent":72.17,"KongZai90_Json":"{\"Uab\":361.127,\"Ubc\":359.264,\"Uca\":356.952,\"Uv\":359.114,\"Uabv\":362.295,\"Ubcv\":360.947,\"Ucav\":358.13,\"Uvv\":360.457,\"Iab\":0.0,\"Ibc\":0.0,\"Ica\":0.0,\"Iv\":0.0,\"Pa\":0.0,\"Pb\":0.0,\"Pc\":0.0,\"Psum\":0.0,\"Pay\":0.0,\"Pby\":0.0,\"Pcy\":0.0,\"SunHao\":0.0,\"Current\":0.0,\"Hz\":49.99}","KongZai100_Json":"{\"Uab\":401.774,\"Ubc\":399.374,\"Uca\":396.352,\"Uv\":399.167,\"Uabv\":403.015,\"Ubcv\":401.105,\"Ucav\":397.572,\"Uvv\":400.564,\"Iab\":0.0,\"Ibc\":0.0,\"Ica\":0.0,\"Iv\":0.0,\"Pa\":0.0,\"Pb\":0.0,\"Pc\":0.0,\"Psum\":0.0,\"Pay\":0.0,\"Pby\":0.0,\"Pcy\":0.0,\"SunHao\":0.0,\"Current\":0.0,\"Hz\":50.019}","KongZai110_Json":"{\"Uab\":440.516,\"Ubc\":439.467,\"Uca\":436.523,\"Uv\":438.835,\"Uabv\":441.789,\"Ubcv\":441.218,\"Ucav\":437.773,\"Uvv\":440.26,\"Iab\":0.0,\"Ibc\":0.0,\"Ica\":0.0,\"Iv\":0.0,\"Pa\":0.0,\"Pb\":0.0,\"Pc\":0.0,\"Psum\":0.0,\"Pay\":0.0,\"Pby\":0.0,\"Pcy\":0.0,\"SunHao\":0.0,\"Current\":0.0,\"Hz\":50.031}","FuZai_Json":"{\"ShiPinTemp\":0.0,\"Uab\":440.203,\"Ubc\":438.196,\"Uca\":435.428,\"Uv\":437.942,\"Iab\":2.917,\"Ibc\":2.849,\"Ica\":2.909,\"Iv\":2.892,\"Pa\":271.347,\"Pb\":267.636,\"Pc\":298.292,\"Psum\":837.276,\"SunHao\":1036.787,\"ZukangV\":4.545}","NaiYa_Json":"{\"A_V\":800.84,\"B_V\":801.139,\"C_V\":800.61,\"A_I\":0.617,\"B_I\":0.753,\"C_I\":0.755,\"HZ\":149.989,\"Time\":20.0}"}',true));

    }

    private function curl_get_https($url) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36\r\n");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  // 跳过检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);  // 跳过检查
        $tmpInfo = curl_exec($curl);
        curl_close($curl);
        return $tmpInfo;   //返回json对象

        //        $ch = curl_init();
        //        curl_setopt($ch, CURLOPT_HEADER, false);
        //        curl_setopt($ch, CURLOPT_URL, $url);
        //        curl_setopt($ch, CURLOPT_SSLVERSION,3);
        //        $result = curl_exec($ch);
        //        curl_close($ch);
        //        return $result;
    }

    private function stripslashes_deep($value){
        $value = is_array($value) ?
            array_map('stripslashes_deep', $value) :
            stripslashes($value);
        return $value;
    }


    /**
     * 将pdf转化为单一png图片
     * @param string $pdf pdf所在路径 （/www/pdf/abc.pdf pdf所在的绝对路径）
     * @param string $path 新生成图片所在路径 (/www/pngs/)
     *
     * @throws Exception
     */
    private function pdf2png2($pdf, $path) {
        try {
            $im = new Imagick();
            $im->setCompressionQuality(100);
            $im->setResolution(120, 120);//设置分辨率 值越大分辨率越高
            $im->readImage($pdf);

            $canvas = new Imagick();
            $imgNum = $im->getNumberImages();
            //$canvas->setResolution(120, 120);
            foreach($im as $k => $sub) {
                $sub->setImageFormat('png');
                //$sub->setResolution(120, 120);
                $sub->stripImage();
                $sub->trimImage(0);
                $width = $sub->getImageWidth() + 10;
                $height = $sub->getImageHeight() + 10;
                if($k + 1 == $imgNum) {
                    $height += 10;
                } //最后添加10的height
                $canvas->newImage($width, $height, new ImagickPixel('white'));
                $canvas->compositeImage($sub, Imagick::COMPOSITE_DEFAULT, 5, 5);
            }

            $canvas->resetIterator();
            $canvas->appendImages(true)->writeImage($path.microtime(true).'.png');
        } catch(\Exception $e) {
            throw $e;
        }
    }
}
